package com.kantboot.system.user.web.controller;

import com.kantboot.system.user.domain.dto.InitSelfInfoDTO;
import com.kantboot.system.user.domain.vo.SysUserOfSelfVO;
import com.kantboot.system.user.service.IUserSelfService;
import com.kantboot.util.common.result.RestResult;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/system-user-web/userSelf")
public class UserSelfController {

    @Resource
    private IUserSelfService service;

    /**
     * 获取本身信息
     */
    @RequestMapping("/getSelf")
    public RestResult<SysUserOfSelfVO> getSelf() {
        return RestResult.success(service.getSelf(),"getSuccess","获取成功");
    }

    /**
     * 获取本身用户的id
     */
    @RequestMapping("/getSelfId")
    public RestResult<Long> getSelfId() {
        return RestResult.success(service.getSelfId(),"getSuccess","获取成功");
    }

    /**
     * 修改密码（不建议使用，建议使用安全的）
     */
    @RequestMapping("/changePassword")
    public RestResult<Void> changePassword(
            @RequestParam("oldPassword") String oldPassword,
            @RequestParam("newPassword") String newPassword) {
        service.changePassword(oldPassword, newPassword);
        return RestResult.success(null,"changeSuccess","修改成功");
    }

    /**
     * 修改密码（安全）
     */
    @RequestMapping("/changePasswordWithSecurity")
    public RestResult<Void> changePasswordWithSecurity(
            @RequestParam("oldPassword") String oldPassword,
            @RequestParam("newPassword") String newPassword) {
        service.changePasswordWithSecurity(oldPassword, newPassword);
        return RestResult.success(null,"changeSuccess","修改成功");
    }

    /**
     * 初始化个人信息
     */
    @RequestMapping("/initSelfInfo")
    public RestResult<SysUserOfSelfVO> initSelfInfo(@RequestBody InitSelfInfoDTO dto) {
        return RestResult.success(service.initSelfInfo(dto),"initSuccess","初始化成功");
    }

}
